package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.service.MessageService;
import cn.edu.nit.sys.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author 罗文斌
 * @Date 2023/5/17
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @GetMapping
    public R getSysMessageList(Page<Map<String, String>> page, String uid) {
        return messageService.getSysMessageList(page, uid);
    }

    @PutMapping("/{id}")
    public R changeReadStatus(@PathVariable("id") String id) {
        return messageService.changeReadStatus(id);
    }

    @GetMapping("/read/{id}")
    public R getNotReadMessage(@PathVariable("id") String id) {
        return messageService.getNotReadMessage(id);
    }

    @GetMapping("/user")
    public R getMessageList(Page<Map<String, String>> page, String userId1, String userId2) {
        return messageService.getMessageList(page, userId1, userId2);
    }

    @PutMapping("/read")
    public R updateMessageStatus(@RequestBody Map<String, String> params) {
        String target = params.get("target");
        String source = params.get("source");
        return messageService.readMessage(target, source);
    }
}
